<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>javascript 验证表单111</title>
    <script>
        function validateForm() {
            var name = document.getElementById("name").value;
            var userpwd = document.getElementById("userpwd").value;
            var userpwd2 = document.getElementById("userpwd2").value;
            if (name == "") {
                alert("请输入姓名");
                return false;
            }
            if (userpwd == "") {
                alert("请输入密码");
                return false;
            }
            if (userpwd2 == "") {
                alert("请再次输入密码");
                return false;
            }
            if (userpwd != userpwd2) {
                alert("两次输入的密码不一致");
                return false;
            }
            return true;
        }
    </script>
</head>
<body>
    <form action="" method="post" onsubmit="return validateForm()">
        姓名: <input type="text" name="name" id="name"><br>
        密码: <input type="password" name="userpwd" id="userpwd"><br>
        确认: <input type="password" name="userpwd2" id="userpwd2"><br>
        Comment: <input type="submit" name="comment" id="comment" value="  注册"><br>
</html>

    
    

